﻿using NUnit.Framework;
using NUnit.Framework.Constraints;

namespace Dgg.LearnYourTools.NUnit.C_Assertions.f_CustomConstraints
{
	[TestFixture]
	public class _030_GoingCustom
	{
		public class EvenConstraint : Constraint
		{
			public override bool Matches(object current)
			{
				return matches((int)current);
			}

			private bool matches(int current)
			{
				actual = current;
				return current % 2 == 0;
			}

			public override void WriteDescriptionTo(MessageWriter writer)
			{
				writer.WritePredicate("An even integer.");
			}
		}

		[Test]
		public void CustomConstraint()
		{
			Assert.That(2, new EvenConstraint());
			Assert.That(3, new EvenConstraint());
		}
	}
}
